package com.ehome.poct.base.log.service;

import com.ehome.core.service.AbstractCrudServiceImpl;
import com.ehome.poct.base.api.dto.device.TestDeviceDTO;
import com.ehome.poct.base.api.dto.log.TestDeviceErrorLogDTO;
import com.ehome.poct.base.api.virtual.TestDeviceService;
import com.ehome.poct.base.api.virtual.log.TestDeviceErrorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;

/**
 * 错误日志表SerivceImlp
 *
 * @author 路飞
 * @Date 2021-12-22 11:26
 */
@Service
public class TestDeviceErrorLogServiceImlp extends AbstractCrudServiceImpl<TestDeviceErrorLogDTO> implements TestDeviceErrorLogService {

    @Autowired
    TestDeviceService testDeviceService;

    @Override
    protected void preInsert(TestDeviceErrorLogDTO dto, Map<String, Object> map) {
        TestDeviceDTO tdd = new TestDeviceDTO();
        tdd.setSno(dto.getSno());
        TestDeviceDTO testDeviceDTO = testDeviceService.selectOne(tdd);
        Optional.ofNullable(testDeviceDTO).ifPresent(t->dto.setTermClinicId(t.getTermClinicId()));
    }
}